import logging

from config import URL


class RegLoginApi(object):
    def __init__(self, session):
        self.session = session

    def get_img_verify_code(self, r):
        url = URL + "/common/public/verifycode1/{}".format(r)
        response = self.session.get(url=url)
        logging.info("获取注册图片验证码接口返回的响应状态码:{}".format(response.status_code))
        return response

    def get_phone_verify_code(self, phone_v, imgVerifyCode_v, type_v):
        url = URL + "/member/public/sendSms"
        form_data = {"phone": phone_v, "imgVerifyCode": imgVerifyCode_v, "type": type_v}
        response = self.session.post(url=url, data=form_data)
        logging.info("获取注册短信验证码接口返回的响应数据:{}".format(response.json()))
        return response

    def user_register(self, phone_v, password_v, verifycode_v, phone_code_v, dy_server_v, invite_phone_v):
        url = URL + "/member/public/reg"
        form_data = {'phone': phone_v,
                     'password': password_v,
                     'verifycode': verifycode_v,
                     'phone_code': phone_code_v,
                     'dy_server': dy_server_v,
                     'invite_phone ': invite_phone_v
                     }
        response = self.session.post(url=url, data=form_data)
        logging.info("注册接口返回的响应数据:{}".format(response.json()))
        return response

    def user_login(self,keywords_v,password_v):
        url = URL + "/member/public/login"
        form_data = {'keywords': keywords_v,
                     'password': password_v}

        response = self.session.post(url=url, data=form_data)
        logging.info("登录接口返回的响应数据:{}".format(response.json()))
        return response